|
|
|
|
|
|
|
instance of the ActiveX component is accessed by multiple clients, whereas an EXE runs in its own memory space. In addition, with an ActiveX EXE users can run the program, and at the same time other programs can reference and use classes within it. |
|
|
|
|
|
|
|
|
One great feature of Visual Basic is the way it displays information and lists as you are entering code. For example, if you are using the Employee class, Visual Basic can display a list of available properties and methods, as shown in Figure 16.5. |
|
|
|
|
|
|
|
|
Figure 16.5
Feature such as Auto List Member and the
Object Browser work with classes that you create. |
|
|
|
|
|
|
|
|
However, if you have written a method in the class, you often need a way to know valid parameter values. One example of this is the Message Box constants (for example, vbCritical) that are listed as you type a MsgBox statement. Consider the earlier example of the Department property in clsEmployee. Although you allow the users to enter some string values, you are really storing the employee's department as an integer. In addition, unless the users of the class know a list of valid departments, they will not know that MARKETING is an acceptable value. |
|
|
|
|
|
|
|
|
One way to get around this problem is to use an enumeration, or in Visual Basic, an enum. Enumerations allow you to define a group of constants as a data type. You can then use this data type in function parameters. |
|
|
|
|
|
|
|
|
For example, you could define an Enum for employee departments and then redefine the Department property of clsEmployee: |
|
|
|
|
|
|
|
|
Public Enum Departments
Marketing = 101
Accounting = 102
InformationTech =103
Unknown=104
End Enum
Dim nDeptNum As Integer
Public Property Get Department() As Departments
Department = nDeptNum
End Property |
|
|
|
|
|